<template>
  <a-card title="功放状态显示" class="LNBBox">
    <!-- <a-button slot="extra" type='primary' @click="handleQuery">状态查询</a-button> -->
    <a-descriptions size="small" :column="2" bordered style="">
      <!-- <div slot="title" style="padding: 10px 20px 0;">
                LNB设备状态显示 <a-button type='primary' style=" float: right;">LNB状态查询</a-button>
            </div> -->
      <a-descriptions-item label="控制模式">
        {{ desData.controlModel == '0' ? '本控' : desData.controlModel == '1' ? '远控' : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="射频开关">
        {{ desData.switch == '0' ? '关' : desData.switch == '1' ? '开' : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="设备状态">
        {{ desData.equipmentStatus == '0' ? '异常' : desData.equipmentStatus == '1' ? '正常' : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="衰减">
        {{ desData.decay ? desData.decay : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="反射功率">
        {{ desData.reflectedPower ? desData.reflectedPower : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="输出功率">
        {{ desData.outputPower ? desData.outputPower : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="模块温度(℃)">
        {{ desData.temperature ? desData.temperature : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="模块电流(A)">
        {{ desData.electricCurrent ? desData.electricCurrent : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="模块电压(V)">
        {{ desData.temperature ? desData.voltage : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="TCP端口">
        {{ desData.tcpPort ? desData.tcpPort : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="IP地址">
        {{ desData.IPaddress ? desData.IPaddress : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="网关">
        {{ desData.gateway ? desData.gateway : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="子网掩码">
        {{ desData.subnetMask ? desData.subnetMask : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="MAC地址">
        {{ desData.MACaddress ? desData.MACaddress : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="欠压报警">
        {{ HandlingAlarms(desData.alarm, 0) }}
      </a-descriptions-item>
      <a-descriptions-item label="过压报警">
        {{ HandlingAlarms(desData.alarm, 1) }}
      </a-descriptions-item>
      <a-descriptions-item label="超温报警">
        {{ HandlingAlarms(desData.alarm, 2) }}
      </a-descriptions-item>
      <a-descriptions-item label="驻波告警">
        {{ HandlingAlarms(desData.alarm, 3) }}
      </a-descriptions-item>
    </a-descriptions>
  </a-card>
</template>

<script>
import { getAction, httpAction } from '../../../api/manage'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      formLNB: { inputFrequency: '/', outputFrequency: '/' },
      labelCol: { span: 12 },
      wrapperCol: { span: 10 },
      desData: {},
      url: {
        getByChannelCode: '/attr/nmcAttr/getByChannelCode'
      },
      options: [
        { resKey: 'tcpdk', webKey: 'tcpPort', label: 'TCP端口' },
        { resKey: 'ipdz', webKey: 'IPaddress', label: 'IP地址' },
        { resKey: 'wg', webKey: 'gateway', label: '网关' },
        { resKey: 'zwym', webKey: 'subnetMask', label: '子网掩码' },
        { resKey: 'macdz', webKey: 'MACaddress', label: 'MAC地址' },
        { resKey: 'ybk', webKey: 'controlModel', label: '控制模式' },
        { resKey: 'spkg', webKey: 'switch', label: '射频开关' },
        { resKey: 'sbzt', webKey: 'equipmentStatus', label: '设备状态' },
        { resKey: 'sj', webKey: 'decay', label: '衰减' },
        { resKey: 'fsgl', webKey: 'reflectedPower', label: '反射功率' },
        { resKey: 'scgl', webKey: 'outputPower', label: '输出功率' },
        { resKey: 'mkwd', webKey: 'temperature', label: '模块温度' },
        { resKey: 'mkdl', webKey: 'electricCurrent', label: '模块电流' },
        { resKey: 'mkdy', webKey: 'voltage', label: '模块电压' },
        { resKey: 'gj', webKey: 'alarm', label: '告警' }
      ]
    }
  },

  computed: {
    ...mapGetters(['websocketMsg']),
    websocketMsg() {
      return this.$store.state.user.websocketMsg
    }
  },
  watch: {
    websocketMsg: {
      handler(val) {
        // 收到websocket的消息 则请求LNB-状态查询回执包,'===更换webSocket 的cmd'
        if (val) {
          console.log('攻防信息')
          let msg = JSON.parse(val)
          if (msg.cmd === 'gf_sx') {
            this.getData()
          }
        }
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    HandlingAlarms(val, type) {
      let str = parseInt(val, 16)
        .toString(2)
        .padStart(8, '0')
      let arr = str.split('').reverse()
      let reslut = ''
      if (type == 0) {
        reslut = arr[0] == 1 ? '欠压' : '正常'
      } else if (type == 1) {
        reslut = arr[1] == 1 ? '过压' : '正常'
      } else if (type == 2) {
        reslut = arr[2] == 1 ? '超温' : '正常'
      } else if (type == 3) {
        reslut = arr[3] == 1 ? '告警' : '正常'
      }
      return reslut
    },
    getData() {
      let temp = {
        channelCode: '功放'
      }
      getAction(this.url.getByChannelCode, temp).then(res => {
        if (res.success) {
          res.result.forEach(i => {
            let key = this.options.find(j => j.resKey == i.attrName).webKey
            if (key) {
              if (i.attrName == 'gj') {
                // this.$set(this.desData,key,'05')
                this.$set(this.desData, key, i.originalValue)
              } else {
                this.$set(this.desData, key, i.parseValue)
              }
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.LNBBox {
  height: 100%;
  overflow-y: scroll !important;
}
</style>

<style>
.LNBBox .ant-card-body {
  padding: 10px !important;
}

.ant-descriptions-bordered .ant-descriptions-item-label,
.ant-descriptions-item-content,
.ant-descriptions-title {
  background: transparent !important;
  color: #fff;
}
</style>
